package com.smarthome.web.property.controller.statisticsquery;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smarthome.core.statisticsquery.OwenrStatisticsService;
import com.smarthome.domain.bean.ShAccount;
import com.smarthome.domain.vo.boss.TimeRange;
import com.smarthome.domain.vo.boss.Combobox;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;
import com.smarthome.web.property.utils.UserHolder;

/**
 * 业主统计控制类
 * @author cyj
 *
 */
@Controller
@RequestMapping("/owenrStatisticsController")
public class OwenrStatisticsController {

    @Resource
    private OwenrStatisticsService owenrStatisticsService;
    

    /**
     * 
    * @Title: dataGrid 
    * @Description: TODO(获得业主数据表格) 
    * @param account
    * @param page
    * @param request
    * @return
    * DataGrid
    * @throws 
    * @author cyj
     */
    @RequestMapping("/dataGrid")
    @ResponseBody
    public DataGrid dataGrid(ShAccount account, PageHelper page,TimeRange timeRange) {
    	if(timeRange.getStartGmtCreate() != null) {
    		account.addQueryData("startGmtCreate", timeRange.getStartGmtCreate());
    	}
    	if(timeRange.getEndGmtCreate() != null) {
    		account.addQueryData("endGmtCreate", timeRange.getEndGmtCreate());
    	}
    	if(timeRange.getStartGmtModify() != null) {
    		account.addQueryData("startGmtModify", timeRange.getStartGmtModify());
    	}
    	if(timeRange.getEndGmtModify() != null) {
    		account.addQueryData("endGmtModify", timeRange.getEndGmtModify());
    	}
    	if(timeRange.getStartLastLoginTime() != null) {
    		account.addQueryData("startLastLoginTime", timeRange.getStartLastLoginTime());
    	}
    	if(timeRange.getEndLastLoginTime() != null) {
    		account.addQueryData("endLastLoginTime", timeRange.getEndLastLoginTime());
    	}
    	
    	Long residenceId = UserHolder.getCurrentResidenceId();
    	account.setResidenceId(residenceId);
    	
        return owenrStatisticsService.dataGrid(account, page);
    }

    /**
     * 
    * @Title: getComboData 
    * @Description: TODO(获取业主统计需要的combo数据) 
    * @return
    * Map<String,Object>
    * @throws 
    * @author cyj
     */
    @RequestMapping("/getComboData")
    @ResponseBody
    public Map<String,Object> getComboData() {
    	Map<String,Object> result = new HashMap<>();
    	List<Combobox> sex = owenrStatisticsService.sex(false);
    	List<Combobox> type = owenrStatisticsService.type(false);
    	List<Combobox> status = owenrStatisticsService.status(false);
    	result.put("sex", sex);
    	result.put("type", type);
    	result.put("status", status);
    	return result;
    }
}
